﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Jzy.BLL.HR;
using Jzy.Model.Contact;
using Frame.Lib.Utilities;
using Frame.Lib.Common;
using Frame.Lib.Core.Dept;
using Frame.Lib.Core.Tree;
using Frame.Lib.Core;


public partial class Contact_Inner_CardList : PageBase
{
    private int DeptID
    {
        get
        {
            return int.Parse(StrUtil.DecryptUrl(Request["DeptID"]));
        }
    }
    private EmployeeBO _emp = new EmployeeBO();

    private ListMode ContactListMode
    {
        get
        {
            if (AppSession.Session["ContactListMode"] == null)
            {
                AppSession.Session["ContactListMode"] = ListMode.Card;
            }
            return (ListMode)AppSession.Session["ContactListMode"];
        }
        set
        {
            AppSession.Session["ContactListMode"] = value;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lblDirName.Text = (new TreeBO<DeptInfo>(STableName.Dept)).GetName(DeptID);
            BindList();
        }
        AddAttr();
        JSUtil.SetTableHeight(content.ClientID, 60);
    }

    private void AddAttr()
    {        
        JSUtil.ClickBtn(lnkDispMode, btnDispMode);
        JSUtil.ClickBtn(lnkExport, btnExport);
    }

    private void BindList()
    {
        DataTable dt = _emp.GetContactList(DeptID);
        
        DataView dv = dt.DefaultView;
        if (txtCondition.Text.Trim() != "")
        {
            dv.RowFilter = "Name like '%" + txtCondition.Text.Trim() + "%'";
        }
        rptList.DataSource = dv;
        rptList.DataBind();
        if (dv.Count == 0)
        {
            content.Style["margin-right"] = "0px";
        }
        lblCount.Text = "[ 共 " + dv.Count + " 个联系人 ]&nbsp;";       
    }
    protected void btnDispMode_Click(object sender, EventArgs e)
    {
        ContactListMode = ListMode.List;
        Response.Redirect("List.aspx?DeptID=" + StrUtil.EncryptUrl(DeptID), true);
    }
   
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindList();
    }

    protected void btnExport_Click(object sender, EventArgs e)
    {
        BindList();
        _emp.ExprotExcel(rptList.DataSource);
    }
  
}
